<?php

namespace app\api\model;

use think\Model;
use app\api\model\BaseModel;

class Theme extends BaseModel{
    //
    protected $hidden = ['delete_time','update_time','topic_img_id','head_img_id'];

    public function topicImg(){
    	return $this->belongsTo('Image','topic_img_id','id');
    }

    public function headImg(){
    	return $this->belongsTo('Image','head_img_id','id');
    }

    public function products(){
    	// 关联模型,多对多表名(或模型),前一个表的字段,后一个表的字段
    	return $this->belongsToMany('Product','theme_product','product_id','theme_id');
    }

    public static function getThemeWithProducts($id){
        $theme = self::with('products,topicImg,headImg')->find($id);
        return $theme;
    }

    
}
